import { Component, Input, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ActivatedRoute } from '@angular/router';
import { res } from 'src/app/common/Interface';
import { NzMessageService } from 'ng-zorro-antd/message';
@Component({
  selector: 'app-out-log',
  templateUrl: './out-log.component.html',
  styleUrls: ['./out-log.component.less'],
})
export class OutLogComponent implements OnInit {
  @Input('commodity_id') commodity_id: number;

  constructor(private http: HttpClient, private message: NzMessageService) {}
  noevent(evt) {
    return;
  }
  ngOnInit() {
    this.getList();
  }
  condition = {
    pageSize: 6,
    pageNo: 1,
  };
  total = 0;
  getList() {
    this.http
      .post('/outLog/list', {
        commodity_id: this.commodity_id,
        ...this.condition,
      })
      .subscribe(({ code, data, msg }: res) => {
        if (code == 200) {
          const { total } = data;
          this.total = total;
          this.listOfData = data.data;
          this.listOfData.map((item) => (item.show = false));
        }
      });
  }
  listOfData = [];

  startTime: number = 0;
  timeOut: any = null;
  touchstart(data: any) {
    data.show = false;
    if (data.state) {
      this.startTime = Date.now();
      this.timeOut = setTimeout(() => {
        data.show = true;
        clearTimeout(this.timeOut);
      }, 1000);
    } else {
      data.show = false;
    }
  }

  touchmove() {
    this.timeOut && clearTimeout(this.timeOut);
  }
  clickMe(data: any) {
    const bkl = confirm('确定要标记这条记录为退货吗？');
    data.show = false;
    if (bkl) {
      this.http
        .get(`/outLog/del`, {
          params: {
            id: data.id,
          },
        })
        .subscribe(({ code, msg }: res) => {
          this.message[code == 200 ? 'success' : 'error'](msg);
        });
    }
  }

  touchend() {
    if (Date.now() - this.startTime < 1000) {
      clearTimeout(this.timeOut);
    }
  }
}
